package codeTop;

public class lcr54 {
    public int findTargetNode(TreeNode root, int cnt) {
        dfs(root,cnt);
        return res;
    }

    private void dfs(TreeNode root, int cnt) {
        if (res != -1||root==null) {
            return;
        }
        dfs(root.right,cnt);
        if (++num == cnt) {
            res = root.val;
            return;
        }
        dfs(root.left,cnt);
    }
    int num = 0;
    int res = -1;
}
